package com.celesea.auth.user.service;

import com.celesea.auth.user.dao.UserPermDao;
import com.celesea.auth.user.entity.UserPerm;
import com.celesea.framework.entity.BusEntity;
import com.celesea.framework.service.AbstractBaseService;
import com.celesea.framework.util.EnvUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * @Creator yuanhaitao
 */
@Service
public class UserPermServiceImpl extends AbstractBaseService<UserPerm> implements UserPermService {

    @Autowired
    private UserPermDao userPermDao;

    @Override
    public List<UserPerm> findByUser(String userId) {
        return userPermDao.selectByExample(buildExample(userId));
    }

    @Override
    public int deleteByUser(String userId) {
        return userPermDao.deleteByExample(buildExample(userId));
    }

    private Example buildExample(String userId) {
        Example example = new Example(UserPerm.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo(BusEntity.TALENT_ID, EnvUtil.getTenantId())
                .andEqualTo("userId", userId);
        return example;
    }
}
